﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RolesManage_AddOrDeleteRole : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
        //if (User.Identity.IsAuthenticated)
        //{
        //    if (!IsPostBack)
        //    {
        //        BindRoles();
        //    }
        //}
        //else
        //{
        //    Response.Redirect("~/SignIn.aspx");
        //}

        if (!IsPostBack)
        {
            BindRoles();
        }
       
    }
    protected void Add_Click(object sender, EventArgs e)
    {
        string str1 = "此角色已存在!";
        string str2 = "添加成功!";

        if (Roles.RoleExists(RoleID.Text.ToString().Trim()))
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str1 + "');</script>");      
        }
        else
        {
            Roles.CreateRole(RoleID.Text.ToString().Trim());
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str2 + "');</script>");         
            BindRoles();
        }
    }

    protected void BindRoles()
    {
        GridView1.DataSource = Roles.GetAllRoles();
        GridView1.DataBind();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Roles.DeleteRole(GridView1.SelectedRow.Cells[1].Text.ToString());
        BindRoles();
        GridView1.SelectedIndex = -1;
    }
}